package com.aiti.lulian.flow.business;

import cn.hutool.core.util.IdUtil;
import com.aiti.lulian.flow.dto.FlowParamDto;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * description:
 * auth fcb
 * date 2025-09-04 10:34
 **/
@Service("test-flow")
@Slf4j
public class TestBusinessFlowService implements BusinessFlowService {

    /**
     * 保存业务数据
     *
     * @param flowParam
     * @return 业务数据id
     * @throws Exception
     */
    @Override
    public String saveBusinessData(FlowParamDto flowParam)  {
        return IdUtil.simpleUUID();
    }

    /**
     * 流程发起前执行。
     * 抛出任何异常都不会发起流程
     *
     * @param flowParam
     * @throws Exception
     */
    @Override
    public void beforeStartFlow(FlowParamDto flowParam) {
        log.info("流程发起前执行，参数：{}", JSON.toJSONString(flowParam));
        try {
            log.info("测试异常");
        }catch (Exception e) {
            throw e;
        }
    }

    /**
     * 节点通过后执行
     *
     * @param flowInstanceId 流程实例id
     * @param nodeKey        当前节点key
     * @param businessId     业务数据id
     * @throws Exception
     */
    @Override
    public void passNode(String flowInstanceId, String nodeKey, String businessId) {
        log.info("节点通过后执行， flowInstanceId:{}, nodeKey:{}, businessId:{}", flowInstanceId, nodeKey, businessId);
    }

    /**
     * 节点完成后执行
     *
     * @param flowInstanceId 流程实例id
     * @param businessId     业务数据id
     * @throws Exception
     */
    @Override
    public void flowComplete(String flowInstanceId, String businessId) {
        log.info("节点完成后执行， flowInstanceId:{}, businessId:{}", flowInstanceId, businessId);
    }

    /**
     * 节点驳回后执行
     *
     * @param flowInstanceId 流程实例id
     * @param nodeKey        当前节点key
     * @param businessId     业务数据id
     * @throws Exception
     */
    @Override
    public void flowReject(String flowInstanceId, String nodeKey, String businessId){
        log.info("节点驳回后执行， flowInstanceId:{}, nodeKey:{}, businessId:{}", flowInstanceId, nodeKey, businessId);
    }
}
